Imports OMANE.Common.UI
Imports System.Collections.ObjectModel
Imports System.Windows
Imports Infragistics.Windows.Chart
Imports System.Windows.Controls
Imports System.ComponentModel
Imports PTIC_GestionBDD
Imports Microsoft.Practices.Prism.Commands


''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Public Class VMCorrespondance
    Inherits VMSectionBase

    Private manager As BddManager
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Sub New()
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Sub New(ByVal manager As BddManager)
        Title = "CORRESPONDANCE"
        Me.manager = manager
    End Sub

    Sub New(ByVal editmode As Boolean)
        Title = "CORRESPONDANCE"
    End Sub

    '#Region "Variables privées"
    '    Private _model As Model
    '#End Region

    '#Region "Constructeur"
    '    ''' <summary>
    '    ''' Constructeur
    '    ''' </summary>
    '    ''' <remarks></remarks>
    '    Public Sub New(ByVal Model As Model, ByVal DisplayName As String, ByVal Command As ICommand)
    '        MyBase.New(DisplayName, Command)
    '        _model = Model
    '        Dim traitTbleEncours As tableBDD = _model.Univers.listeTraitements.TraitTbleEncours
    '        'Ajouter une capture de l'évènement indiquant que le nom de la table a changé
    '    End Sub
    '    Public Sub New()
    '    End Sub
    '#End Region

    '#Region "Propriétés"


    ''' <summary>
    ''' Liste des champs attendus pour l'import des données d'encours
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property VariablesEntreeEncours() As ObservableDictionary(Of String, Correspondance)
        Get

            Dim mdlomane = ModuleIndicateurs.AppInstance.GetService(Of OMANE.Common.Model.Interfaces.IModelOMANE)()

            Dim tableBdd As tableBDD = mdlomane.ListeTraitements(PTIC_Util.nomTraitTbleEncours)

            Return tableBdd.ListeChampsSortie

            '  Return manager.ListeTraitements.TraitTbleEncours.ListeChampsSortie
        End Get
    End Property

    ''' <summary>
    ''' Liste des champs disponibles dans la table sélectionnée par l'utilisateur
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property VariablesEntreeBase() As Dictionary(Of String, Correspondance)
        Get
            Dim mdlomane = ModuleIndicateurs.AppInstance.GetService(Of OMANE.Common.Model.Interfaces.IModelOMANE)()


            Dim tableBdd As tableBDD = mdlomane.ListeTraitements(PTIC_Util.nomTraitTbleEncours)

            Return tableBdd.ListeChampsEntree
            'Return manager.ListeTraitements.TraitTbleEncours.ListeChampsEntree
        End Get
    End Property

    'Private _cmdVisualiserChampsEntree As DelegateCommand
    'Public ReadOnly Property cmdVisualiserChampsEntree As DelegateCommand
    '    Get
    '        If _cmdVisualiserChampsEntree Is Nothing Then
    '            _cmdVisualiserChampsEntree = New DelegateCommand(AddressOf VisualiserChampsEntree)
    '        End If
    '        Return _cmdVisualiserChampsEntree
    '    End Get
    'End Property

    Private _cmdChargerFichierCorresp As DelegateCommand
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property cmdChargerFichierCorresp() As DelegateCommand
        Get
            If _cmdChargerFichierCorresp Is Nothing Then
                _cmdChargerFichierCorresp = New DelegateCommand(AddressOf ChargerFichierCorrespondances)
            End If
            Return _cmdChargerFichierCorresp
        End Get
    End Property

    Private _cmdEnregistrerFichierCorresp As DelegateCommand
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property cmdEnregistrerFichierCorresp() As DelegateCommand
        Get
            If _cmdEnregistrerFichierCorresp Is Nothing Then
                _cmdEnregistrerFichierCorresp = New DelegateCommand(AddressOf EnregistrerFichierCorrespondances)
            End If
            Return _cmdEnregistrerFichierCorresp
        End Get
    End Property

    'Private _cmdEditerCorrespondance As DelegateCommand
    'Public ReadOnly Property cmdEditerCorrespondance As DelegateCommand
    '    Get
    '        If _cmdEditerCorrespondance Is Nothing Then
    '            _cmdEditerCorrespondance = New DelegateCommand(AddressOf EditerCorrespondance)
    '        End If
    '        Return _cmdEditerCorrespondance
    '    End Get
    'End Property

    Private _cmdSupprimerCorrespondance As DelegateCommand(Of Correspondance)
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property cmdSupprimerCorrespondance As DelegateCommand(Of Correspondance)
        Get
            If _cmdSupprimerCorrespondance Is Nothing Then
                _cmdSupprimerCorrespondance = New DelegateCommand(Of Correspondance)(AddressOf SupprimerCorrespondance)
            End If
            Return _cmdSupprimerCorrespondance
        End Get
    End Property

    '#End Region

    '#Region "Commandes"
    '    ''' <summary>
    '    ''' Méthode appelée lorsqu'un champs attendu en entrée de la table d'encours est renseigné par glisser déposer
    '    ''' </summary>
    '    ''' <remarks></remarks>
    '    Public Sub paramChampsCible(ByVal sender As Object, ByVal e As System.Windows.DragEventArgs)
    '        Dim chCible As Correspondance = CType(sender.DataContext, KeyValuePair(Of String, Correspondance)).Value
    '        Dim chSource As Correspondance = e.Data.GetData(GetType(KeyValuePair(Of String, Correspondance))).Value
    '        Dim tableEncours As tableBDD = _model.Univers.listeTraitements.TraitTbleEncours
    '        Dim result As Boolean = _model.Univers.listeTraitements.TraitTbleEncours.setChSortieFormuleEgaleChampsEntree(chSource.description, chCible.description)
    '        '_model.Univers.listeTraitements.getTraitTbleEncours.ListeChampsSortie.setDescription(chCible.description, "totot")
    '        'chCible.typeChEntree = typeChEntreeMapping.CONSTANT
    '        'VariablesEntreeEncours.NotifyCollectionChange(chCible.description, chCible)
    '    End Sub

    ''' <summary>
    ''' Procédure de chargement d'un mapping des champs de la table d'encours
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ChargerFichierCorrespondances()
        'Dim openFileDialog1 As New Microsoft.Win32.OpenFileDialog
        'openFileDialog1.InitialDirectory = PTIC_Util.csteEmplacementParametrage
        'openFileDialog1.Filter = "Corresp. encours (*.oma)|*.oma"
        'If openFileDialog1.ShowDialog() Then
        '    'Chargement des correspondances sauvegardées
        '    baseListeChampsSortieTable.load(openFileDialog1.FileName, manager.ListeTraitements.TraitTbleEncours)
        'End If

        Dim openFileDialog1 As New Microsoft.Win32.OpenFileDialog
        openFileDialog1.InitialDirectory = PTIC_Util.csteEmplacementParametrage
        openFileDialog1.Filter = "Corresp. encours (*.oma)|*.oma"
        If openFileDialog1.ShowDialog() Then
            'Chargement des correspondances sauvegardées

            Dim mdlomane = ModuleIndicateurs.AppInstance.GetService(Of OMANE.Common.Model.Interfaces.IModelOMANE)()

            If Not mdlomane.ListeTraitements.ContainsKey(PTIC_Util.nomTraitTbleEncours) Then Return

            '    Return

            baseListeChampsSortieTable.load(openFileDialog1.FileName, mdlomane.ListeTraitements(PTIC_Util.nomTraitTbleEncours))
        End If
    End Sub

    ''' <summary>
    ''' Enregistrer le mapping en cours de la table d'encours
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub EnregistrerFichierCorrespondances()
        Dim SaveFileDialog1 As New Microsoft.Win32.SaveFileDialog
        SaveFileDialog1.InitialDirectory = PTIC_Util.csteEmplacementParametrage
        SaveFileDialog1.Filter = "Fichiers de correspondance encours (*.oma)|*.oma"
        If SaveFileDialog1.ShowDialog() Then
            'Sauvegarde des objets métiers
            Dim mapTxGar As baseListeChampsSortieTable = manager.ListeTraitements.TraitTbleEncours.ListeChampsSortie
            mapTxGar.save(SaveFileDialog1.FileName)
            MsgBox("Le mapping courant de la table d'encours a été enregistré sous " & SaveFileDialog1.FileName)
        End If
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>

    Private Sub SupprimerCorrespondance(ByVal CorrespondanceASupprimer As Correspondance)
        CorrespondanceASupprimer.setChEntree(Nothing)
    End Sub

    '    Private Sub EditerCorrespondance(ByVal Correspondance As Object)
    '        Dim correspAEditer As Correspondance = Correspondance
    '        Dim VMCorresp As New ViewModelCorrespondance(correspAEditer)
    '        Dim ui = ModuleTauxGaranti._app.GetService(Of IUIService)()
    '        ui.ShowMessage(VMCorresp)
    '    End Sub
    '#End Region

End Class
